//右下角弹出提醒
$(function () {
    $.messager.show({
        title:'My Title',
        msg:'<div style="color: red;">Message never be closed.</div>',
        timeout:5000,
        showType:'fade'
    });
    $("#center").on('click','.box-pointer', function () {
        $(this).parent().next('.box-body').slideToggle("slow");
        if($(this).find('.fa-chevron-down')) {
            $(this).removeClass("fa-chevron-down").addClass("fa-chevron-up");
        } else {
            $(this).removeClass("fa-chevron-up").addClass("fa-chevron-down");
        }
    });

    function initChart() {
        var dom = document.getElementById("myCharts");
        var myChart = echarts.init(dom);
        var app = {};
        var colors = ['#550AF2', '#52cdd5', '#0DED2C', '#83af9b', '#c8c8a9'];
        option = null;
        option = {
            title: {
                text: '网站访问统计'
            },
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            legend: {
                data:['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
            },
            toolbox: {
                show: true,
                /*orient: 'vertical',*/
                feature: {
                    dataView: {readOnly: false},
                    /*dataZoom: {},*/
                    magicType: {type: ['line', 'bar', 'stack', 'tiled']},
                    /*restore: {},*/
                    saveAsImage: {}
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis : [
                {
                    type : 'category',
                    boundaryGap : false,
                    data : ['周一','周二','周三','周四','周五','周六','周日']
                }
            ],
            yAxis : [
                {
                    type : 'value'
                }
            ],
            series : [
                {
                    name:'邮件营销',
                    type:'line',
                    stack: '总量',
                    areaStyle: {normal: {}},
                    data:[120, 132, 101, 134, 90, 230, 210]
                },
                {
                    name:'联盟广告',
                    type:'line',
                    stack: '总量',
                    areaStyle: {normal: {}},
                    data:[220, 182, 191, 234, 290, 330, 310]
                },
                {
                    name:'视频广告',
                    type:'line',
                    stack: '总量',
                    areaStyle: {normal: {}},
                    data:[150, 232, 201, 154, 190, 330, 410]
                },
                {
                    name:'直接访问',
                    type:'line',
                    stack: '总量',
                    areaStyle: {normal: {}},
                    data:[320, 332, 301, 334, 390, 330, 320]
                },
                {
                    name:'搜索引擎',
                    type:'line',
                    stack: '总量',
                    label: {
                        normal: {
                            show: true,
                            position: 'top'
                        }
                    },
                    areaStyle: {normal: {}},
                    data:[820, 932, 901, 934, 1290, 1330, 1320]
                }
            ],
            color: colors
        };
        if (option && typeof option === "object") {
            myChart.setOption(option, true);
        }
        myChart.resize({'width':'auto', 'height':'auto'});
    }
    initChart();
});
(function () {
    var dateObj = (function(){
        // 默认为当前系统时间
        var _date = new Date();
        return {
            getDate : function(){
                return _date;
            },
            setDate : function(date) {
                _date = date;
            }
        };
    })();
    function setTitle() {
        var _year = dateObj.getDate().getFullYear();
        var _month = dateObj.getDate().getMonth() + 1;
        _month = (_month > 9) ? ("" + _month) : ("0" + _month);
        document.getElementById("ym").innerHTML = _year+"年"+_month+"月";
    }
    function paintBox() {
        var calBody = document.getElementById("calBody");
        var _html = "";

        var _year = dateObj.getDate().getFullYear();
        var _month = dateObj.getDate().getMonth();
        var _day = 0;
        var _firstDay = new Date(_year, _month, 1);  // 当前月第一天
        var _thisDate = null;
        var _thisStr = '';
        var _thisDay = '01';

        var _todayCls = '';
        var _weekCls = '';
        var _dayCls = '';
        var _lunar = new Object();
        for(var i = 0; i < 42; i++) {
            _thisDate = new Date(_year, _month, i + 1 - _firstDay.getDay());
            _thisStr = formatDate(_thisDate);
            _thisDay = _thisDate.getDate()>9 ? _thisDate.getDate() : '0' +_thisDate.getDate()
            _day = _thisDate.getDay();
            _lunar = calendar.solar2lunar(_thisDate.getFullYear(), _thisDate.getMonth()+1, _thisDate.getDate());
            if(_thisStr == formatDate(new Date())) {
                _todayCls = ' selected';
            } else {
                _todayCls = '';
            }
            if(_day == 0 || _day == 6) {
                _weekCls = ' weekend';
            } else {
                _weekCls = '';
            }
            if(_thisDate.getMonth() != _month) {
                _day = ' no-day';
            } else {
                _day = ' day';
            }

            _html += '<div class="cell'+_todayCls+_weekCls+_day+'" data-date="'+_thisStr+'"><span>'+_thisDay+'</span><span>'+_lunar.IDayCn+'</span></div>';
        }
        calBody.innerHTML = _html;
    }
    function init() {
        setTitle(); // 设置顶部标题栏中的 年、月信息
        paintBox();
    }
    init();


    /**
     * 日期转化为字符串， 4位年+2位月+2位日
     */
    function formatDate(date) {
        var _year = date.getFullYear();
        var _month = date.getMonth() + 1;    // 月从0开始计数
        var _d = date.getDate();

        _month = (_month > 9) ? ("" + _month) : ("0" + _month);
        _d = (_d > 9) ? ("" + _d) : ("0" + _d);
        return _year + '-' + _month + '-' + _d;
    }
    setInterval(function () {
        var d = new Date();
        var _h = d.getHours() < 10 ? "0"+d.getHours() : d.getHours();
        var _m = d.getMinutes() < 10 ? "0"+d.getMinutes() : d.getMinutes();
        var _s = d.getSeconds() < 10 ? "0"+d.getSeconds() : d.getSeconds();
        document.getElementById("time").innerHTML=_h+":"+_m+":"+_s;
    }, 1000);

})();